import dt from '@dt/dt'
import table from '@/components/dt/table/render.js'
import nameOpt from '@/biz/option/name.js'
import dateOpt from '@/biz/option/date.js'

function options(vm, isAudit = false) {
  return [{
      field: 'companyName',
      title: '所属组织',
      minWidth: 150,
    },
    {
      field: 'cityName',
      title: '所属城市',
      minWidth: 110
    },
    {
      field: 'housesName',
      title: '案场名称',
      minWidth: 160,
    },
    {
      field: 'ruleName',
      title: '佣金规则名称',
      minWidth: 150,
    },
    {
      field: 'commissionWayStr',
      minWidth: 100,
      header: {
        filter: {
          title: '结佣方式',
          key: 'commissionWay',
          placeholder: '请选择',
          select: {
            options: dt.dictInfo().CommissionWayEnum
          }
        }
      }
    },
    {
      field: 'productNames',
      title: '产品',
      minWidth: 150,
    },
    {
      title: '有效期',
      minWidth: 250,
      slots: {
        default: (params, h) => {
          return [h('div', params.row.startDate.split(' ')[0] + ' ~ ' + params.row.endDate.split(' ')[0])]
        }
      }
    },
    {
      field: 'submitterName',
      minWidth: 100,
      header: {
        filter: nameOpt.create({
          key: 'submitterId',
          title: '提交人'
        })
      }
    },
    {
      minWidth: 150,
      header: {
        filter: dateOpt.range({
          title: '提交日期',
          startKey: 'submitterStartTime',
          endKey: 'submitterEndTime'
        })
      },
      slots: {
        default: (params, h) => {
          return [h('div', params.row.submitterTime.split(' ')[0])]
        }
      }
    },
    {
      field: 'auditName',
      minWidth: 100,
      header: {
        filter: nameOpt.create({
          key: 'auditId',
          title: '审核人'
        })
      }
    },
    {
      minWidth: 150,
      header: {
        filter: dateOpt.range({
          title: '审核日期',
          startKey: 'auditStartTime',
          endKey: 'auditEndTime'
        })
      },
      slots: {
        default: (params, h) => {
          return table.cell.text(h, {
            value: params.row.auditTime ? params.row.auditTime.split(' ')[0] : '-'
          })
        }
      }
    },
    {
      title: '状态',
      minWidth: 100,
      slots: {
        default: (params, h) => {
          return table.cell.text(h, {
            value: params.row.ruleStatusStr,
            color: params.row.ruleStatus == '3' ? 'red' : null
          })
        }
      }
    },
    {
      field: 'handles',
      title: '操作',
      width: isAudit ? 100 : 230,
      fixed: 'right',
      cell: (item) => {
        let btn = []
        if (item.ruleStatus == 1) {
          if (isAudit) {
            btn.push({
              title: '审核',
              event: 'onAudit',
              code: '0210010201',
            })
          } else {
            btn.push({
              title: '撤回',
              event: 'onRecall',
              code: '0210010102',
            })
          }
        } else if (!isAudit && (item.ruleStatus == 2 || item.ruleStatus == 3)) {
          btn.push({
            title: '重新发起',
            event: 'onResend',
            code: '0210010103',
          })
        }
        btn.push({
          title: '查看',
          event: 'onDetail',
        })
        if (!isAudit) {
          btn.push({
            title: '复制模板',
            event: 'onCopy',
            code: '0210010101',
          })
        }
        if (!isAudit && item.ruleStatus == 2) {
          btn.push({
            title: '删除',
            event: 'onDelete',
            code: '0210010104',
          })
        }
        return {
          btn
        }
      }
    }
  ]
}

export default {
  options
}
